package homework.api.day04._cp;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ListDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("three");
        list.add("nine");
        list.add("six");
        list.add("five");
        list.add("three");
        System.out.println("list:"+list);

        System.out.println("获取第三个元素："+list.get(2));

        System.out.println("获取被替换的元素："+list.set(2,"6666"));
        System.out.println("替换后的list:"+list);

        System.out.println("获取被删除的元素："+list.remove(2));
        System.out.println("删除后的list:"+list);

        list.add(2,"9999");
        System.out.println("add插入后的list:"+list);

        List<String> subList = list.subList(2,5);
        System.out.println("subList:"+subList);
        list.set(2,"753951");
        System.out.println("list修改后：list"+list);
        System.out.println("list修改后：subList"+subList);


        Set<String> set = new HashSet<>();
        set.addAll(list);
        System.out.println("去重后的set"+set);

    }
}
